package item;

import java.nio.ByteBuffer;

import io.Packet;

public class EquipChangedItem extends ChangedItem {
	protected int index;
	protected Equipment equip;
	
	protected EquipChangedItem(int index, Equipment equip) {
		super(TYPE_COMPLEX, ChangedItemType.EQUIP, false);

		this.index = index;
		this.equip = equip;
	}

	@Override
	public void pack(Packet pt) {
		pt.put(ChangedItem.TYPE_COMPLEX);
		pt.put(id);
		if (equip == null) {
			byte[] bytes = new byte[2];
			bytes[0] = (byte) index;
			bytes[1] = 0;
			pt.put(bytes);
		} else {
			byte[] bytes = new byte[2];
			bytes[0] = (byte) index;
			bytes[1] = 1;
			byte[] eBytes = equip.toClientBytes();
			ByteBuffer buffer = ByteBuffer.allocate(bytes.length
					+ eBytes.length);
			buffer.put(bytes);
			buffer.put(eBytes);
			pt.put(buffer.array());
		}
	}

	@Override
	public boolean merge(ChangedItem other) {
		return false;
	}

	public boolean isBroadcast(){
		return false;
	}
	
	public void makeBroadcastPacket(Packet pt){
	}
}
